package com.unittec.drainage.gateway.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.netflix.zuul.filters.RouteLocator;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.unittec.drainage.gateway.filter.GatewayRouteLocatorFilter;
import com.unittec.drainage.provider.service.HystrixRestTemplateService;

@Configuration
@EnableConfigurationProperties({ZuulProperties.class})
public class GateWayServerConfig {
    @Autowired
    protected ZuulProperties zuulProperties;

    @Autowired
    protected ServerProperties server;

    @Autowired
    HystrixRestTemplateService hystrixRestTemplateService;

    @Bean
    public GatewayRouteLocatorConfig gatewayRouteLocator() {
        return new GatewayRouteLocatorConfig(this.server.getServlet().getContextPath(), zuulProperties);
    }

    @Bean
    public GatewayRouteLocatorFilter geaderPreDecorationFilter(RouteLocator routeLocator) {
        return new GatewayRouteLocatorFilter(routeLocator, this.server.getServlet().getContextPath(),
            hystrixRestTemplateService);
    }
}
